import React from 'react'

const ComA = (props) => {
  return <div>我是子组件A接收到的值：{props.msg}</div>
}
class ComB extends React.Component {
  render() {
    return (
      <button
        onClick={() => {
          this.props.changeMsg('我是子组件B传的新的值')
        }}
      >
        点击我给父组件传值
      </button>
    )
  }
}
export default class App extends React.Component {
  state = {
    msg: '我是旧的值',
  }

  changeMsg = (msg1) => {
    this.setState({
      msg: msg1,
    })
  }
  render() {
    // 需求：B像A传值
    return (
      <>
        {/* 父传子 */}
        <ComA msg={this.state.msg}></ComA>
        {/* 子传父 */}
        <ComB changeMsg={this.changeMsg}></ComB>
      </>
    )
  }
}
